import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;

@WebServlet(name = "TimePrinter")
public class TimePrinter extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置响应内容类型,及其编码格式支持中文
        response.setContentType("text/html;charset=UTF-8");
        //设置字符打印输出流
        PrintWriter out = response.getWriter();
        SimpleDateFormat ft = new SimpleDateFormat("yyyy.MM.dd  hh:mm:ss E a ");
        out.println("<center><h1>当前日期和时间如下:</h1></center>");
        out.println("<center><h2>" + ft.format(new Date()) + "</h2></center>");
    }
}
